﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;

namespace Fraktalysator
{
	static class FileSystem
	{
		public static string DirectoryUserData { get; private set; }
		public static string FileUIMemory { get; private set; }
		public static string FileExceptionLog { get; private set; }
		public static string FileUpdateTrack { get; private set; }
		public static string FileDataSetDump { get; private set; }

		static FileSystem()
		{
			FileSystem.DirectoryUserData = Path.Combine(System.Environment.CurrentDirectory, "UserData");
			FileSystem.FileUIMemory = Path.Combine(FileSystem.DirectoryUserData, "UIMemory.xml");
			FileSystem.FileExceptionLog = Path.Combine(System.Environment.CurrentDirectory, "ExceptionLog.txt");
			FileSystem.FileUpdateTrack = Path.Combine(FileSystem.DirectoryUserData, "UpdateTrack.xml");
			FileSystem.FileDataSetDump = Path.Combine(FileSystem.DirectoryUserData, "DataSetDump.dat");

			PropertyInfo[] pis = typeof(FileSystem).GetProperties(BindingFlags.Public | BindingFlags.Static);
			foreach (PropertyInfo pi in pis)
			{
				if (pi.Name.StartsWith("Directory") == true)
					FileSystem.EnsureDirectoryExists((string)pi.GetValue(null, null));
			}
		}

		private static void EnsureDirectoryExists(string directory)
		{
			if (Directory.Exists(directory) == false)
				Directory.CreateDirectory(directory);
		}
	}
}
